let fs = require("fs"),
  stdin = process.stdin,
  stdout = process.stdout;
fs.readdir(process.cwd(), (err, files) => {
  console.log(" ");
  if (!files.length) {
    return console.log("No files to show!");
  }
  console.log("  Select which file or directory you want to see\n");
  function file(i) {
    let fileName = files[i];
    fs.stat(__dirname + "/" + fileName, function (err, stat) {
      if (stat.isDirectory) {
        console.log(`${i}-isDirectory  ${fileName}`);
      } else {
        console.log(`${i}  ${fileName}`);
      }
    });
    i++;
    if (i === files.length) {
      read();
    } else {
      file(i);
    }
  }
  file(0);
});
function read() {
  console.log("");
  process.stdout.write("Enter your choice:");
  stdin.resume();
  stdin.setEncoding("utf8");
}
